<template>
  <div 
    class="navbar" 
    :class="{ 'navbar-collapsed': !isExpanded }" 
    @mouseenter="expand" 
    @mouseleave="handleMouseLeave"
  >
    <div class="nav-content">
      <el-menu
        :default-active="activeIndex"
        class="nav-menu"
        :collapse="!isExpanded"
        @select="handleSelect"
      >
        <el-menu-item index="1" class="menu-item">
          <i class="el-icon-s-home"></i>
          <span class="title">项目</span>
        </el-menu-item>
        <el-menu-item index="2" class="menu-item">
          <i class="el-icon-monitor"></i>
          <span class="title">智慧大窗</span>
        </el-menu-item>
        <el-menu-item index="4" class="menu-item">
          <i class="el-icon-chat-dot-round"></i>
          <span class="title">知识图谱问答</span>
        </el-menu-item>
        <el-menu-item index="5" class="menu-item">
          <i class="el-icon-search"></i>
          <span class="title">图谱检索</span>
        </el-menu-item>
<!--      <el-menu-item index="6">-->
<!--        <i class="el-icon-search"></i>-->
<!--        <span class="title">测试</span>-->
<!--      </el-menu-item>-->
      </el-menu>

      <div class="navbar-footer" :class="{ 'footer-collapsed': !isExpanded }">
        <el-button
          icon="el-icon-switch-button"
          class="logout-btn"
          @click="logout"
        >
          <span v-show="isExpanded">退出登录</span>
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapMutations, mapActions } from 'vuex';

export default {
  name: 'Navbar',
  data() {
    return {
      activeIndex: '1',
      userId: null,
      isExpanded: false,
      // eslint-disable-next-line no-sparse-arrays
      childRouteList: [,'/', '/index', '/chat', '/tutorial', '/systemdesign','/graphShow'],
    }
  },
  computed: {
    ...mapGetters(['userInfo', 'allPageNo', 'ownPageNo']),
  },
  methods: {
    ...mapMutations(['setGraphProjectId', 'setShowCreatePanel']),
    ...mapActions([
      'userLogout',
      'getUserInfo',
      'getAllListByPageNo',
      'getOwnListByPageNo',
      'getAllListAmount',
      'getOwnListAmount',
    ]),
    createNewGraph() {
      this.setShowCreatePanel(true);
    },
    logout() {
      localStorage.removeItem('coin-token');
      this.$router.push('/user');
    },
    handleSelect(key) {
      this.activeIndex = key;
      const path = this.childRouteList[key];
      this.$router.push(path);
    },
    expand() {
      this.isExpanded = true
    },
    collapse() {
      this.isExpanded = false
    },
    toggleUserPanel: function() {
      this.showUserPanel = !this.showUserPanel;
    },
    handleMouseLeave() {
      if (!this.showUserPanel) {
        this.collapse();
      }
    }
  }
}
</script>

<style scoped>
.navbar {
  width: 240px;
  height: 100vh;
  background-color: #1a1f37;
  position: fixed;
  left: 0;
  top: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  overflow: hidden;
}

.navbar-collapsed {
  width: 64px;
}

.nav-content {
  width: 240px;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.title {
  color: #ffffff;
  opacity: 1;
  transition: opacity 0.2s ease-in-out;
}

.navbar-collapsed .title {
  opacity: 0;
}

.nav-menu {
  flex: 1;
  border: none;
  background-color: transparent;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

:deep(.el-menu) {
  border-right: none;
  background-color: transparent;
}

:deep(.el-menu-item) {
  height: 50px;
  line-height: 50px;
  color: rgba(255, 255, 255, 0.7);
  margin: 8px 0;
  border-radius: 4px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

:deep(.el-menu-item:hover) {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
  transform: translateX(4px);
}

:deep(.el-menu-item.is-active) {
  background-color: #4080ff;
  color: #fff;
  margin: 8px 10px;
  transform: scale(1.02);
}

:deep(.el-menu--collapse) {
  width: 64px;
}

.navbar-footer {
  padding: 20px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.footer-collapsed {
  padding: 20px 10px;
}

.logout-btn {
  width: 100%;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  white-space: nowrap;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  transform: translateY(-2px);
}

.menu-item i {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.navbar-collapsed .menu-item:hover i {
  transform: scale(1.2);
}
</style>
